/**
 * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
 *
 * This library is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free
 * Software Foundation; either version 2.1 of the License, or (at your option)
 * any later version.
 *
 * This library is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
 * details.
 */

package com.vportal.portlet.vcms.model.impl;

import com.liferay.portal.kernel.bean.AutoEscapeBeanHandler;
import com.liferay.portal.kernel.json.JSON;
import com.liferay.portal.kernel.util.DateUtil;
import com.liferay.portal.kernel.util.GetterUtil;
import com.liferay.portal.kernel.util.ProxyUtil;
import com.liferay.portal.kernel.util.StringBundler;
import com.liferay.portal.kernel.util.StringPool;
import com.liferay.portal.model.CacheModel;
import com.liferay.portal.model.impl.BaseModelImpl;

import com.vportal.portlet.vcms.model.VcmsAttachedMessage;
import com.vportal.portlet.vcms.model.VcmsAttachedMessageModel;
import com.vportal.portlet.vcms.model.VcmsAttachedMessageSoap;

import java.io.Serializable;

import java.sql.Types;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * The base model implementation for the VcmsAttachedMessage service. Represents a row in the &quot;VcmsAttachedMessage&quot; database table, with each column mapped to a property of this class.
 *
 * <p>
 * This implementation and its corresponding interface {@link com.vportal.portlet.vcms.model.VcmsAttachedMessageModel} exist only as a container for the default property accessors generated by ServiceBuilder. Helper methods and all application logic should be put in {@link VcmsAttachedMessageImpl}.
 * </p>
 *
 * @author hai
 * @see VcmsAttachedMessageImpl
 * @see com.vportal.portlet.vcms.model.VcmsAttachedMessage
 * @see com.vportal.portlet.vcms.model.VcmsAttachedMessageModel
 * @generated
 */
@JSON(strict = true)
public class VcmsAttachedMessageModelImpl extends BaseModelImpl<VcmsAttachedMessage>
	implements VcmsAttachedMessageModel {
	/*
	 * NOTE FOR DEVELOPERS:
	 *
	 * Never modify or reference this class directly. All methods that expect a vcms attached message model instance should use the {@link com.vportal.portlet.vcms.model.VcmsAttachedMessage} interface instead.
	 */
	public static final String TABLE_NAME = "VcmsAttachedMessage";
	public static final Object[][] TABLE_COLUMNS = {
			{ "messageId", Types.VARCHAR },
			{ "groupId", Types.BIGINT },
			{ "companyId", Types.BIGINT },
			{ "createdDate", Types.TIMESTAMP },
			{ "createdByUser", Types.VARCHAR },
			{ "articleId", Types.VARCHAR },
			{ "content", Types.VARCHAR },
			{ "readMessage", Types.BOOLEAN }
		};
	public static final String TABLE_SQL_CREATE = "create table VcmsAttachedMessage (messageId VARCHAR(75) not null primary key,groupId LONG,companyId LONG,createdDate DATE null,createdByUser VARCHAR(200) null,articleId VARCHAR(200) null,content VARCHAR(2000) null,readMessage BOOLEAN)";
	public static final String TABLE_SQL_DROP = "drop table VcmsAttachedMessage";
	public static final String ORDER_BY_JPQL = " ORDER BY vcmsAttachedMessage.createdDate DESC";
	public static final String ORDER_BY_SQL = " ORDER BY VcmsAttachedMessage.createdDate DESC";
	public static final String DATA_SOURCE = "liferayDataSource";
	public static final String SESSION_FACTORY = "liferaySessionFactory";
	public static final String TX_MANAGER = "liferayTransactionManager";
	public static final boolean ENTITY_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.entity.cache.enabled.com.vportal.portlet.vcms.model.VcmsAttachedMessage"),
			true);
	public static final boolean FINDER_CACHE_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.finder.cache.enabled.com.vportal.portlet.vcms.model.VcmsAttachedMessage"),
			true);
	public static final boolean COLUMN_BITMASK_ENABLED = GetterUtil.getBoolean(com.liferay.util.service.ServiceProps.get(
				"value.object.column.bitmask.enabled.com.vportal.portlet.vcms.model.VcmsAttachedMessage"),
			true);
	public static long ARTICLEID_COLUMN_BITMASK = 1L;
	public static long GROUPID_COLUMN_BITMASK = 2L;
	public static long READMESSAGE_COLUMN_BITMASK = 4L;

	/**
	 * Converts the soap model instance into a normal model instance.
	 *
	 * @param soapModel the soap model instance to convert
	 * @return the normal model instance
	 */
	public static VcmsAttachedMessage toModel(VcmsAttachedMessageSoap soapModel) {
		VcmsAttachedMessage model = new VcmsAttachedMessageImpl();

		model.setMessageId(soapModel.getMessageId());
		model.setGroupId(soapModel.getGroupId());
		model.setCompanyId(soapModel.getCompanyId());
		model.setCreatedDate(soapModel.getCreatedDate());
		model.setCreatedByUser(soapModel.getCreatedByUser());
		model.setArticleId(soapModel.getArticleId());
		model.setContent(soapModel.getContent());
		model.setReadMessage(soapModel.getReadMessage());

		return model;
	}

	/**
	 * Converts the soap model instances into normal model instances.
	 *
	 * @param soapModels the soap model instances to convert
	 * @return the normal model instances
	 */
	public static List<VcmsAttachedMessage> toModels(
		VcmsAttachedMessageSoap[] soapModels) {
		List<VcmsAttachedMessage> models = new ArrayList<VcmsAttachedMessage>(soapModels.length);

		for (VcmsAttachedMessageSoap soapModel : soapModels) {
			models.add(toModel(soapModel));
		}

		return models;
	}

	public static final long LOCK_EXPIRATION_TIME = GetterUtil.getLong(com.liferay.util.service.ServiceProps.get(
				"lock.expiration.time.com.vportal.portlet.vcms.model.VcmsAttachedMessage"));

	public VcmsAttachedMessageModelImpl() {
	}

	public String getPrimaryKey() {
		return _messageId;
	}

	public void setPrimaryKey(String primaryKey) {
		setMessageId(primaryKey);
	}

	public Serializable getPrimaryKeyObj() {
		return _messageId;
	}

	public void setPrimaryKeyObj(Serializable primaryKeyObj) {
		setPrimaryKey((String)primaryKeyObj);
	}

	public Class<?> getModelClass() {
		return VcmsAttachedMessage.class;
	}

	public String getModelClassName() {
		return VcmsAttachedMessage.class.getName();
	}

	@JSON
	public String getMessageId() {
		if (_messageId == null) {
			return StringPool.BLANK;
		}
		else {
			return _messageId;
		}
	}

	public void setMessageId(String messageId) {
		_messageId = messageId;
	}

	@JSON
	public long getGroupId() {
		return _groupId;
	}

	public void setGroupId(long groupId) {
		_columnBitmask |= GROUPID_COLUMN_BITMASK;

		if (!_setOriginalGroupId) {
			_setOriginalGroupId = true;

			_originalGroupId = _groupId;
		}

		_groupId = groupId;
	}

	public long getOriginalGroupId() {
		return _originalGroupId;
	}

	@JSON
	public long getCompanyId() {
		return _companyId;
	}

	public void setCompanyId(long companyId) {
		_companyId = companyId;
	}

	@JSON
	public Date getCreatedDate() {
		return _createdDate;
	}

	public void setCreatedDate(Date createdDate) {
		_columnBitmask = -1L;

		_createdDate = createdDate;
	}

	@JSON
	public String getCreatedByUser() {
		if (_createdByUser == null) {
			return StringPool.BLANK;
		}
		else {
			return _createdByUser;
		}
	}

	public void setCreatedByUser(String createdByUser) {
		_createdByUser = createdByUser;
	}

	@JSON
	public String getArticleId() {
		if (_articleId == null) {
			return StringPool.BLANK;
		}
		else {
			return _articleId;
		}
	}

	public void setArticleId(String articleId) {
		_columnBitmask |= ARTICLEID_COLUMN_BITMASK;

		if (_originalArticleId == null) {
			_originalArticleId = _articleId;
		}

		_articleId = articleId;
	}

	public String getOriginalArticleId() {
		return GetterUtil.getString(_originalArticleId);
	}

	@JSON
	public String getContent() {
		if (_content == null) {
			return StringPool.BLANK;
		}
		else {
			return _content;
		}
	}

	public void setContent(String content) {
		_content = content;
	}

	@JSON
	public boolean getReadMessage() {
		return _readMessage;
	}

	public boolean isReadMessage() {
		return _readMessage;
	}

	public void setReadMessage(boolean readMessage) {
		_columnBitmask |= READMESSAGE_COLUMN_BITMASK;

		if (!_setOriginalReadMessage) {
			_setOriginalReadMessage = true;

			_originalReadMessage = _readMessage;
		}

		_readMessage = readMessage;
	}

	public boolean getOriginalReadMessage() {
		return _originalReadMessage;
	}

	public long getColumnBitmask() {
		return _columnBitmask;
	}

	@Override
	public VcmsAttachedMessage toEscapedModel() {
		if (_escapedModelProxy == null) {
			_escapedModelProxy = (VcmsAttachedMessage)ProxyUtil.newProxyInstance(_classLoader,
					_escapedModelProxyInterfaces,
					new AutoEscapeBeanHandler(this));
		}

		return _escapedModelProxy;
	}

	@Override
	public Object clone() {
		VcmsAttachedMessageImpl vcmsAttachedMessageImpl = new VcmsAttachedMessageImpl();

		vcmsAttachedMessageImpl.setMessageId(getMessageId());
		vcmsAttachedMessageImpl.setGroupId(getGroupId());
		vcmsAttachedMessageImpl.setCompanyId(getCompanyId());
		vcmsAttachedMessageImpl.setCreatedDate(getCreatedDate());
		vcmsAttachedMessageImpl.setCreatedByUser(getCreatedByUser());
		vcmsAttachedMessageImpl.setArticleId(getArticleId());
		vcmsAttachedMessageImpl.setContent(getContent());
		vcmsAttachedMessageImpl.setReadMessage(getReadMessage());

		vcmsAttachedMessageImpl.resetOriginalValues();

		return vcmsAttachedMessageImpl;
	}

	public int compareTo(VcmsAttachedMessage vcmsAttachedMessage) {
		int value = 0;

		value = DateUtil.compareTo(getCreatedDate(),
				vcmsAttachedMessage.getCreatedDate());

		value = value * -1;

		if (value != 0) {
			return value;
		}

		return 0;
	}

	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}

		VcmsAttachedMessage vcmsAttachedMessage = null;

		try {
			vcmsAttachedMessage = (VcmsAttachedMessage)obj;
		}
		catch (ClassCastException cce) {
			return false;
		}

		String primaryKey = vcmsAttachedMessage.getPrimaryKey();

		if (getPrimaryKey().equals(primaryKey)) {
			return true;
		}
		else {
			return false;
		}
	}

	@Override
	public int hashCode() {
		return getPrimaryKey().hashCode();
	}

	@Override
	public void resetOriginalValues() {
		VcmsAttachedMessageModelImpl vcmsAttachedMessageModelImpl = this;

		vcmsAttachedMessageModelImpl._originalGroupId = vcmsAttachedMessageModelImpl._groupId;

		vcmsAttachedMessageModelImpl._setOriginalGroupId = false;

		vcmsAttachedMessageModelImpl._originalArticleId = vcmsAttachedMessageModelImpl._articleId;

		vcmsAttachedMessageModelImpl._originalReadMessage = vcmsAttachedMessageModelImpl._readMessage;

		vcmsAttachedMessageModelImpl._setOriginalReadMessage = false;

		vcmsAttachedMessageModelImpl._columnBitmask = 0;
	}

	@Override
	public CacheModel<VcmsAttachedMessage> toCacheModel() {
		VcmsAttachedMessageCacheModel vcmsAttachedMessageCacheModel = new VcmsAttachedMessageCacheModel();

		vcmsAttachedMessageCacheModel.messageId = getMessageId();

		String messageId = vcmsAttachedMessageCacheModel.messageId;

		if ((messageId != null) && (messageId.length() == 0)) {
			vcmsAttachedMessageCacheModel.messageId = null;
		}

		vcmsAttachedMessageCacheModel.groupId = getGroupId();

		vcmsAttachedMessageCacheModel.companyId = getCompanyId();

		Date createdDate = getCreatedDate();

		if (createdDate != null) {
			vcmsAttachedMessageCacheModel.createdDate = createdDate.getTime();
		}
		else {
			vcmsAttachedMessageCacheModel.createdDate = Long.MIN_VALUE;
		}

		vcmsAttachedMessageCacheModel.createdByUser = getCreatedByUser();

		String createdByUser = vcmsAttachedMessageCacheModel.createdByUser;

		if ((createdByUser != null) && (createdByUser.length() == 0)) {
			vcmsAttachedMessageCacheModel.createdByUser = null;
		}

		vcmsAttachedMessageCacheModel.articleId = getArticleId();

		String articleId = vcmsAttachedMessageCacheModel.articleId;

		if ((articleId != null) && (articleId.length() == 0)) {
			vcmsAttachedMessageCacheModel.articleId = null;
		}

		vcmsAttachedMessageCacheModel.content = getContent();

		String content = vcmsAttachedMessageCacheModel.content;

		if ((content != null) && (content.length() == 0)) {
			vcmsAttachedMessageCacheModel.content = null;
		}

		vcmsAttachedMessageCacheModel.readMessage = getReadMessage();

		return vcmsAttachedMessageCacheModel;
	}

	@Override
	public String toString() {
		StringBundler sb = new StringBundler(17);

		sb.append("{messageId=");
		sb.append(getMessageId());
		sb.append(", groupId=");
		sb.append(getGroupId());
		sb.append(", companyId=");
		sb.append(getCompanyId());
		sb.append(", createdDate=");
		sb.append(getCreatedDate());
		sb.append(", createdByUser=");
		sb.append(getCreatedByUser());
		sb.append(", articleId=");
		sb.append(getArticleId());
		sb.append(", content=");
		sb.append(getContent());
		sb.append(", readMessage=");
		sb.append(getReadMessage());
		sb.append("}");

		return sb.toString();
	}

	public String toXmlString() {
		StringBundler sb = new StringBundler(28);

		sb.append("<model><model-name>");
		sb.append("com.vportal.portlet.vcms.model.VcmsAttachedMessage");
		sb.append("</model-name>");

		sb.append(
			"<column><column-name>messageId</column-name><column-value><![CDATA[");
		sb.append(getMessageId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>groupId</column-name><column-value><![CDATA[");
		sb.append(getGroupId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>companyId</column-name><column-value><![CDATA[");
		sb.append(getCompanyId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createdDate</column-name><column-value><![CDATA[");
		sb.append(getCreatedDate());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>createdByUser</column-name><column-value><![CDATA[");
		sb.append(getCreatedByUser());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>articleId</column-name><column-value><![CDATA[");
		sb.append(getArticleId());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>content</column-name><column-value><![CDATA[");
		sb.append(getContent());
		sb.append("]]></column-value></column>");
		sb.append(
			"<column><column-name>readMessage</column-name><column-value><![CDATA[");
		sb.append(getReadMessage());
		sb.append("]]></column-value></column>");

		sb.append("</model>");

		return sb.toString();
	}

	private static ClassLoader _classLoader = VcmsAttachedMessage.class.getClassLoader();
	private static Class<?>[] _escapedModelProxyInterfaces = new Class[] {
			VcmsAttachedMessage.class
		};
	private String _messageId;
	private long _groupId;
	private long _originalGroupId;
	private boolean _setOriginalGroupId;
	private long _companyId;
	private Date _createdDate;
	private String _createdByUser;
	private String _articleId;
	private String _originalArticleId;
	private String _content;
	private boolean _readMessage;
	private boolean _originalReadMessage;
	private boolean _setOriginalReadMessage;
	private long _columnBitmask;
	private VcmsAttachedMessage _escapedModelProxy;
}